﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

public partial class Client : System.Web.UI.MasterPage
{
    DADataContext da = new DADataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (string.IsNullOrEmpty(Convert.ToString(Session["user"])))
            {
                LoadMenuUser();
            }
            else
            {
                var quyen = (from q in da.Accounts where q.Taikhoan == Session["user"].ToString() select q.Quyen).FirstOrDefault();
                if (quyen == 0)
                {
                    LoadMenuUser();
                }
                else
                {
                    var q2 = (from q in da.TaikhoanChucnangs where q.Taikhoan == Session["user"].ToString() && q.Machucnang != 0 select q).Count();
                    if (q2 == 0)
                    {
                        LoadMenuUser();
                    }
                    else
                    {
                        LoadMenuAd();
                    }
                }
            }             
        }
    }
    void LoadMenuUser()
    {
        var menua = from m in da.Menus where m.Hienthi == 1 && m.Tenmenu != "Quản trị" orderby m.Vitri ascending select m;
        lbmenu.Text = "<ul>";
        foreach (var mn in menua)
        {
            lbmenu.Text += "<li><a href=\"" + mn.Duongdan + "\" class=\"b_loai1\">" + mn.Tenmenu + "</a></li>";
        }
        lbmenu.Text += "</ul>";
    }
    void LoadMenuAd()
    {
        var menua = from m in da.Menus where m.Hienthi == 1 orderby m.Vitri ascending select m;
        lbmenu.Text = "<ul>";
        foreach (var mn in menua)
        {
            lbmenu.Text += "<li><a href=\"" + mn.Duongdan + "\" class=\"b_loai1\">" + mn.Tenmenu + "</a></li>";
        }
        lbmenu.Text += "</ul>";
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (search.Text != "")
        {
            Response.Redirect("/Online/Search/" + search.Text + ".html");
        }
    }
}
